package system;

import java.io.File;
import java.io.IOException;

public class PowerUp extends Actor{
	Actor owner; // The Actor that the PowerUp applies to
	Boolean absorbed = false; // has it been "eaten"

	// States
	final int POWERUP_HEAL = 1;
	final int POWERUP_BULLET = 2;

	public PowerUp(Actor actor, float x, float y, int type) throws IOException{
		super("Powerup", new AnimatedSprite(new File("assets/sprites/powerup-b.png"), 16, 16, true, 34), x, y, -1, -1, 0, -1);

		owner = actor;
		setState(type);
		if(type == POWERUP_HEAL){
			setSprite(new AnimatedSprite(new File("assets/sprites/powerup-h.png"), 16, 16, true, 34));
		}
		
		setPower(25);

	}
	
	public void isAbsorbed() {
		setLifetime(100);
		absorbed = true;
		
	}
	
	public boolean getAbsorbedState(){
		return absorbed;
	}

	@Override
	public void update(){
		
		sprite.update();

		if(!absorbed){
			x = x + xvel;
			y = y + yvel;
			
			if (x <= 0 || x >= 464){
				xvel = -1 * xvel;
			}
			if (y <= 0 || y >= 254){
				yvel = -1 * yvel;
			}
		}
		else{ // set it offscreen to make it "invisible" LOL
			x = 500;
			y = 0;
		}

		// check if we should update a lifetime var
		if (lifetime != -1 && curLifetime < lifetime){
			curLifetime++;
			if (curLifetime >= lifetime){
				remove();
			}
		}
		
	}

	public void remove(){ // remove the powerup
		switch(state){
		case POWERUP_HEAL: 
		{
			
		}
		break;
			case POWERUP_BULLET: {owner.setPower(owner.getPower() - this.getPower());}
		}
		
		setState(-1);
	}

}
